package com.gen.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.gen.entity.User;
import com.gen.web.BaseController;
import com.gen.web.entity.Demo;
@Controller
@RequestMapping("/api")
public class DemoController extends BaseController{
	protected final Logger log = LoggerFactory.getLogger(this.getClass());
	
	@RequestMapping(value = "/demo", method = RequestMethod.GET)
	public Demo test1(
			@RequestParam("username") String username, 
			@RequestParam(value = "terminalType", required = false) String terminalType,
			Model model,HttpServletRequest req) {
		Demo demo = new Demo();
		demo.setName("123");
		demo.setPassWord("123pwd");
		log.info(demo.toString());
		return demo;
	}
	
	@RequestMapping(value = "/{str}", method = RequestMethod.GET)
    public String getUserById(@PathVariable String str,Model model) {
    	User user = this.facadeService.getTestService().getUserByUsername(str);
    	if(user != null){
    		model.addAttribute("name", user.getPassword());
    	}else{
    		model.addAttribute("name", str);
    	}
        return "demo/NewFile"; 
    }

}
